/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StatusScreen.java
 *
 * Created on Sep 9, 2012, 10:14:56 PM
 */

package com.apps.ui;

import com.apps.controllers.ShellController;
import com.apps.utils.StartupHelper;
import com.apps.utils.StatusChecker;
import java.awt.LayoutManager;
import java.util.ArrayList;
import javax.swing.JPanel;

/**
 *
 * @author ARIJIT PAL
 */
public class StatusScreen extends javax.swing.JFrame {
    
    private ArrayList<ShellController> shellList;
    
    private void setAccList(ArrayList<ShellController> shellList){
        this.shellList = shellList;
    }
    public JPanel getPanel(){
        return jPanel1;
    }
    
    /** Creates new form StatusScreen */
    public StatusScreen() {
        initComponents();
        setAccList(StartupHelper.getShellList());
        jPanel1.removeAll();
        if(shellList!=null){
            for(ShellController shell : shellList){
                StatusUI statusUI = new StatusUI();
                statusUI.setShell(shell);
                statusUI.setAccID(shell.getAccID());
                statusUI.setHostName(shell.getHost()+":"+shell.getPort());
                statusUI.setActiveInd(shell.getActiveFlag());
                if(shell.getShellStatus()){
                    statusUI.setFlagCL("green");
                }else{
                    statusUI.setFlagCL("red");
                }
                jPanel1.add(statusUI);
            }
        }
        jPanel1.repaint();
        StatusChecker stsCk = new StatusChecker();
        StartupHelper.setStatusChecker(stsCk);
        stsCk.setUI(jPanel1);
        stsCk.setRefreshFlag(true);
        Thread th = new Thread(stsCk);
        th.start();
        /*jScrollPane1.add(statusUI1);
        jScrollPane1.add(statusUI1);
        jScrollPane1.add(statusUI1);*/
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        statusUI3 = new com.apps.ui.StatusUI();
        statusUI4 = new com.apps.ui.StatusUI();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jScrollPane1.setAutoscrolls(true);

        jPanel1.setLayout(new java.awt.GridLayout(100, 1));
        jPanel1.add(statusUI3);
        jPanel1.add(statusUI4);

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new StatusScreen().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private com.apps.ui.StatusUI statusUI3;
    private com.apps.ui.StatusUI statusUI4;
    // End of variables declaration//GEN-END:variables

}
